package com.example.yls.demoa;

import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import android.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
private android.support.v7.widget.Toolbar my_tb;
private CardView cardView;
private int count=0;
private FloatingActionButton floatingActionButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        my_tb=findViewById(R.id.my_tb);
        setSupportActionBar(my_tb);//不加这句无菜单!!!
       cardView=findViewById(R.id.id_cv);
       floatingActionButton=findViewById(R.id.fab);
       cardView.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               animote();
           }
       });
       floatingActionButton.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               Snackbar.make(floatingActionButton,"我是snackbar",Snackbar.LENGTH_LONG)
                       .setAction("点击", new View.OnClickListener() {
                           @Override
                           public void onClick(View view) {
                               Toast.makeText(MainActivity.this, "snackbar点击事件", Toast.LENGTH_SHORT)
                                       .show();
                           }
                       }).show();
           }
       });
    }
    private void animote() {
        cardView.animate().translationX(100+count).start();
        count+=10;
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
            case R.id.tab_add:
                Toast.makeText(this, "add", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tab_about:
                Toast.makeText(this, "about", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tab_before:
                Toast.makeText(this, "before", Toast.LENGTH_SHORT).show();
                break;

        }
        return super.onOptionsItemSelected(item);
    }
}
